<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property string $user_id
 * @property string $request_url
 * @property string $type
 * @property string $ip
 * @property string $params_json
 * @property string $response_json
 * @property \Carbon\Carbon $update_time
 * @property \Carbon\Carbon $create_time
 */
class ErrorLog extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'error_log';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'username', 'request_url', 'type', 'ip', 'params_json', 'response_json', 'create_time', 'update_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'update_time' => 'datetime', 'create_time' => 'datetime'];

    // 如果你需要隐藏原始的 create_time 字段
    protected array $hidden = ['create_time', 'update_time','request_url','params_json','response_json'];

    // 如果你需要显示新的 createTime 字段
    protected array $appends = ['createTime', 'updateTime', 'requestUrl', 'paramsJson', 'responseJson'];

    public function getCreateTimeAttribute()
    {
        return $this->attributes['create_time'];
    }
    public function getUpdateTimeAttribute()
    {
        return $this->attributes['update_time'];
    }
    public function getRequestUrlAttribute()
    {
        return $this->attributes['request_url'];
    }
    public function getParamsJsonAttribute(){
        return $this->attributes['params_json'];
    }
    public function getResponseJsonAttribute(){
        return $this->attributes['response_json'];
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');

    }

}
